package com.spark.lola.controller.logistics;

import com.alibaba.fastjson.JSONObject;
import com.spark.lola.logistics.service.IndexService;
import com.spark.lola.logistics.vo.ExpensesStatusVo;
import com.spark.lola.logistics.vo.OrderStatusVo;
import com.spark.lola.statistics.entity.StatisticsDriver;
import com.spark.lola.support.common.entity.ShiroUser;
import com.spark.lola.support.common.util.ResponseBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import java.text.ParseException;

/**
 * @author: Zhi-peng wang
 * @date: 2020/05/20 16:54
 * 首页业务接口
 **/
@RestController
@RequestMapping("/api/logistics/index")
@Api(value = "/api/logistics/index", tags = "首页业务接口")
public class IndexController {

    @Autowired
    private IndexService indexService;

    @ApiOperation(value = "业务总统计")
    @ApiImplicitParam(name = "findType", value = "分类", required = true, dataType = "int", paramType = "query")
//    @RequiresPermissions(value = {"m5161", "m5163"}, logical = Logical.OR)
    @RequestMapping(value = "/findAllData", method = RequestMethod.GET)
    public ResponseBean findAllData(int findType, @SessionAttribute ShiroUser shiroUser) throws ParseException {
        StatisticsDriver statisticsDriver = indexService.findAllData(findType, shiroUser);
        JSONObject hardwareData = indexService.findHardwareData();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("statisticsDriver", statisticsDriver);
        jsonObject.put("hardwareData", hardwareData);
        return ResponseBean.success(jsonObject);
    }

    @ApiOperation(value = "业务图表统计")
    @ApiImplicitParam(name = "findType", value = "分类", required = true, dataType = "int", paramType = "query")
//    @RequiresPermissions(value = {"m5161", "m5163"}, logical = Logical.OR)
    @RequestMapping(value = "/findBiData", method = RequestMethod.GET)
    public ResponseBean findBiData(int findType, @SessionAttribute ShiroUser shiroUser) throws ParseException {
        JSONObject jsonObject = indexService.findBiData(findType, shiroUser);
        JSONObject hardwareData = indexService.findHardwareData();
        jsonObject.put("hardwareData", hardwareData);
        return ResponseBean.success(jsonObject);
    }

    @ApiOperation(value = "货运单处理事务")
//    @RequiresPermissions(value = {"m5161", "m5163"}, logical = Logical.OR)
    @RequestMapping(value = "/findOrderStatusData", method = RequestMethod.POST)
    public ResponseBean findHardwareData(@SessionAttribute ShiroUser shiroUser) throws ParseException {
        OrderStatusVo orderStatusVo = indexService.findOrderStatusData();
        return ResponseBean.success(orderStatusVo);
    }

    @ApiOperation(value = "货运支出单处理事务")
//    @RequiresPermissions(value = {"m5161", "m5163"}, logical = Logical.OR)
    @RequestMapping(value = "/findExpensesStatusData", method = RequestMethod.POST)
    public ResponseBean findExpensesStatusData(@SessionAttribute ShiroUser shiroUser) throws ParseException {
        ExpensesStatusVo expensesStatusVo = indexService.findExpensesStatusData();
        return ResponseBean.success(expensesStatusVo);
    }

}
